import pygame
from pygame.locals import *
import pygame.sprite

print "unidades.aliens.aliens_ataque cargado satisfactoriamente"

class AlienAtaque(pygame.sprite.Sprite):
    def __init__(self, linea):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("images/alien1.png").convert_alpha()
        self.linea = linea
        self.linea.unidades.append(self)
        self.rect = self.image.get_rect()
        self.rect.centerx = 1060
        self.rect.centery = self.linea.y
        self.frames = 0
        self.vida = None
        self.ataque = None
        self.velocidad_ataque = None
        self.atacando = False
        self.velocidad = -1
        self.mask = pygame.mask.from_surface(self.image)
    def update(self):
        pass
    def verifica_vida(self):
        if self.vida <= 0:
            self.linea.unidades.remove(self)
            self.kill()
    def avanza(self):
        if not self.atacando:
            if self.rect.right < 0:
                self.kill()
            else:
                self.rect.move_ip(-self.velocidad, 0)
    def recibir_ataque(self, value):
        self.vida -= value


class AlienAtaqueComun(AlienAtaque):
    def __init__(self, linea):
        AlienAtaque.__init__(self, linea)
        self.image = pygame.image.load("images/alien1.png").convert_alpha()
        self.vida = 100
        self.ataque = 10
        self.velocidad = 1
        self.velocidad_ataque = 1
    def update(self):
        self.frames += 1
        if self.frames % 100 > 50:
            self.image = pygame.image.load("images/alien2.png").convert_alpha()
        else:
            if self.frames == 100:
                self.frames = 0
            self.image = pygame.image.load("images/alien1.png").convert_alpha()
        self.verifica_vida()
        self.avanza()